<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="padding-top:10px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters" label-width="100px">
        <el-form-item prop="telephone" label="手机号">
          <el-input v-model="filters.telephone" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item prop="status" label="发送状态">
          <el-select v-model="filters.status"  placeholder="发送状态" style="width:215px">
							 <el-option label="全部" value=""></el-option>
               <el-option label="发送成功" value="0"></el-option>
               <el-option label="发送失败" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="startTime" label="时间">
          <el-date-picker
          v-model="filters.startTime" value-format="yyyy-MM-dd"
          type="date"
          placeholder="开始日期">
        </el-date-picker>
        </el-form-item>
        <el-form-item prop="endTime">
          <el-date-picker
          v-model="filters.endTime" value-format="yyyy-MM-dd"
          type="date"
          placeholder="结束日期">
        </el-date-picker>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
          <el-form-item style="float: right">
            <el-button-group>
              <el-tooltip content="刷新" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
              </el-tooltip>
              <el-tooltip content="列显示" placement="top">
                <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
              </el-tooltip>
              <el-tooltip content="导出" placement="top">
                <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
              </el-tooltip>
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult" :columns="filterColumns" @findPage="findPage"
      :showOperation="false"
      :showBatchDelete="false"
      :showSelection="false"
      ref="CyTable"
    ></cy-table>
  </div>
</template>

<script>
import CyTable from "@/views/Core/JicTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        telephone:'',
        status:'',
        startTime:'',
        endTime:'',
      },
      pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},
      columns: [
        { prop: "id", label: "序号", minWidth: 50 },
        { prop: "telephone", label: "手机号", minWidth: 100 },
        { prop: "code", label: "验证码", minWidth: 100 },
        { prop: "status", label: "发送状态", minWidth: 80 ,formatter: this.statusFormatter},
        { prop: "createTime", label: "创建时间", minWidth: 120 }
	  ],
	  filterColumns:[],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},

      operation: false, // true:新增, false:编辑
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,

    };
  },
  methods: {
    // 获取分页数据
      findPage: function(data) {
        let this_ = this;
        if (this_.filters == undefined || this_.filters == null) {
          this_.filters = {};
        } 
        if(data != null && data.start != null){
          if(data.start != null){
            this.pageRequest.pageNum = data.start;
          }
          if(data.limit != null){
            this.pageRequest.pageSize = data.limit;
          }
        }
        this_.filters.start = this.pageRequest.pageNum;
        this_.filters.limit = this.pageRequest.pageSize;
        this.utils.request.querySmsLogList(this_.filters, function (res) {
          if (res.data == null) {
              res.data = [];
              res.totle = 0;
          }else{
              this_.$refs.CyTable.findPage({content:res.data.rows,total:res.data.total});
          }
        });
      },

    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
        this.findPage(null);
      }
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
   // 处理表格列过滤显示
      initColumns: function () {
        var temp = [];

        $.each(this.columns, function (key, val) {
          temp.push(val);
        });
        this.filterColumns = temp;
      },
      statusFormatter: function(row, column, cellValue, index){
        if(cellValue==0){
          return '成功'
        }else if(cellValue==1){
          return '失败'
        }
      },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "短信验证码下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
    this.initColumns()
    this.findPage()
  }
};
</script>

<style scoped>
</style>
